<?php
require("includes/basic.php");
$client=addslashes($_POST['client-name']);
$client_desc=addslashes($_POST['client-desc']);
$customer=$customerid;
$creator=$distusertypeid;
$client_uname=$_POST['client-uname'];
$client_pass=md5($_POST['client-pass']);
$type=$_POST['client-type'];
$sql=mysql_query("insert into client_master (`client_name`,`client_description`,`user_name`,`password`,`client_type`,`client_created_on`,`client_created_by`) values ('$client','$client_desc','$client_uname','$client_pass','$type',sysdate(),'$creator')");
$getcid=mysql_query("select * from client_master order by client_id desc limit 1");
$cidr=mysql_fetch_array($getcid);
extract($cidr);
$cid=$cidr['client_id'];
$setusertypecli=mysql_query("update client_master set usertypeid=concat('C',$cid) where client_id=$cid");
$sql1=mysql_query("insert into cust_client (`customer_id`,`client_id`) values ('$distusertypeid',concat('C',$cid))");
if($sql1)
	{
		if(isset($_POST['submit']) && $_FILES['uploadedfile']['size'] > 0)
			{
				$fileName = $_FILES['uploadedfile']['name'];
				$tmpName = $_FILES['uploadedfile']['tmp_name'];
				$fileSize = $_FILES['uploadedfile']['size'];
				$fileType = $_FILES['uploadedfile']['type'];
				$fp      = fopen($tmpName, 'r');
				$content = fread($fp, filesize($tmpName));
				$content = addslashes($content);
				fclose($fp);
				if(!get_magic_quotes_gpc())
				{
					$fileName = addslashes($fileName);
				}
				$query = "INSERT INTO client_logo(client_id, name, type, size, content,uploaded_on) VALUES (concat('C',$cid),'$fileName','$fileType','$fileSize','$content',sysdate())";				
				mysql_query($query) or die('Error, query failed'); 				
			}
	}
if($sql)
{
 header("location:view-clients.php");
}
?>